/* 
 * File:   Task.cpp
 * Author: switch
 * 
 * Created on 22 janvier 2013, 16:40
 */

#include "Task.h"

Task::Task(string title, bool isOrdo) : titre(title), ordo(isOrdo) {check=false;Echeance=false;}
Task::Task(string title, bool isOrdo, int nombre) : titre(title), ordo(isOrdo), number(nombre) {check=false;Echeance=false;}


Task::~Task() {
}

void Task::setNumber(int number) {
    this->number = number;
}

int Task::getNumber() const {
    return number;
}

void Task::setOrdo(bool ordo) {
    this->ordo = ordo;
}

bool Task::isOrdo() const {
    return ordo;
}

void Task::setTitre(string titre) {
    this->titre = titre;
}

string Task::getTitre() const {
    return titre;
}


void Task::setDeadLine(string deadLine) {
    this->deadLine = deadLine;
}

string Task::getDeadLine() const {
    return deadLine;
}






//Gestion de la liste des taches
void Task::addTask(Task* t) {
    tasksList.push_back(t);
    taskSort();
}

void Task::removeTask(Task* t) {
    tasksList.remove(t);
}

void Task::setTasksList(list<Task*> tasksList) {
    this->tasksList = tasksList;
}

list<Task*> Task::getTasks() const {
    return tasksList;
}


/*TODO
/!\ Fix sort /!\ 
 */
void Task::taskSort() {
    tasksList.sort();
}

void Task::setEcheance(bool Echeance) {
    this->Echeance = Echeance;
}

bool Task::isEcheance() const {
    return Echeance;
}

void Task::setCheck(bool check) {
    this->check = check;
}

bool Task::isCheck() const {
    return check;
}



string Task::toString() {
    string res = this->getTitre()+"(";

    for (std::list<Task*>::iterator it = tasksList.begin(); it != tasksList.end(); ++it) {
        Task *tmpTask = *it;
        res+=tmpTask->toString();
    }
   
    return res+")";
}


int operator==(Task const &a, Task const &b) {
    if(a.getTitre()==b.getTitre()) return true;
    else return false;
}


bool orderByNumber(const Task &t1,const Task &t2){

    if(t1.getNumber()<t2.getNumber()) {
        return true;
    }
    else {
        return false;
    }
        
}

bool operator < (const Task& a, const Task& b)
    {
      return a.getNumber() < b.getNumber();
    }